
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>绩效配置</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">

    <style>
        .bootstrap-table {
            padding: 20px;
        }
        .jixiao {
            margin-left: 50px;
        }
        #save {
            margin-left: 50px;
            width: 100px;
        }
        .text_ient {
            width: auto;
        }
        .tip {
            display: block;
            color: red;
            margin: 10px 0 0 63px;
        }
    </style>
</head>

<body>
    <div class="tabe_div">
        <p class="p_line text_ient" style="margin-bottom: -10px">
            <a class="find_a">业绩区间：</a>
            <input id="start" type="text" class="form_input text_ient" placeholder="" />
            <a class="find_a" style="margin-right: 10px;">至</a>
            <input id="end" type="text" class="form_input text_ient" placeholder="" />元
            <a class="find_a jixiao">绩效比例：</a>
            <input id="ratio" maxlength="11" type="text" class="form_input text_ient" placeholder="" />%
            <input type="button" value="保存" class="but_find" id="save" />
            <br />
            <strong class="tip">
                请填写整数，填写区间含小不含大
            </strong>
        </p>
        <table data-url="json/data_alae_list.json" id="table" class="table_style" style="margin: 0 auto">
        </table>
    </div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/date/js/laydate.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../../layer_v2.1/layer/layer.js"></script>
    <script type="text/javascript">
        localStorage.setItem('name', '财务管理/绩效配置')
        $(function() {
            $('#save').on('click', function() {
                const performanceMin = $('#start').val();
                const performanceMax = $('#end').val();
                const ratio = $('#ratio').val();

                $.ajax({
                url: baseUrl + "performance/savePerformance",
                method: "Post",
                headers: {
                    "Authorization": JSON.parse(localStorage.getItem('userInfo')).token
                },
                data: {
                    performanceMin,
                    performanceMax,
                    ratio,
                },
                success: function (data) {
                    $('#table').bootstrapTable('refresh');
                    alert(data.message);
                }
                })
            })
            var perm = JSON.parse(localStorage.getItem('userInfo')).perm
            $('#table')
                .bootstrapTable({
                    method: "get",
                    striped: true,
                    singleSelect: false,
                    url: baseUrl + 'performance/selectPerformanceList',
                    dataType: "json",
                    sidePagination: "server",
                    pagination: true, //分页
                    pageSize: 10,
                    pageNumber: 1,
                    search: false, //显示搜索框
                    contentType: "application/x-www-form-urlencoded",
                    ajaxOptions:{
                        headers: {"Authorization": JSON.parse(localStorage.getItem('userInfo')).token}
                    },
                    queryParams: function(params) {
                        params.offset = params.offset / params.limit
                        delete params.order
                        return params
                    },
                    responseHandler: function(res) {
                        var list = res.data.result.records

                        return {
                            rows: list,
                            total: res.data.total
                        }
                    },
                    columns: [{
                        field: 'no',
                        title: '序号',
                        sortable: true,
                        align: "center",
                        formatter: function(value, row, index) {
                            var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
                            var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },{
                        title: '业绩区间',
                        field: '',
                        align: 'center',
                        valign: 'middle',
                        formatter: function(value, row, index) {
                            return `${row.performanceMin}-${row.performanceMax}元`
                        }
                    }, {
                        title: '绩效比例',
                        field: '',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return `${row.ratio}%`;
                        }
                    }, {
                        title: '创建时间',
                        field: 'createDate',
                        align: 'center'
                    }, {
                        title: '创建人',
                        field: 'createName',
                        align: 'center'
                    }, {
                        title: '操作',
                        field: 'oper',
                        align: 'center',
                        formatter: function(value, row) {
                            console.log('row.id', row.id)
                            return `<a href="#" onclick="remove('${row.id}')">删除</a>`
                        }
                    }]
                });
        });


        function remove(id) {
            $.ajax({
                url: baseUrl + "performance/delPerformance",
                method: "Post",
                headers: {
                    "Authorization": JSON.parse(localStorage.getItem('userInfo')).token
                },
                data: {
                    id,
                },
                success: function (data) {
                    $('#table').bootstrapTable('refresh');
                    alert(data.message);
                }
                })
        }
    </script>
</body>

</html>